<template>
  <div id="aCoursesList" class="container">
    <!-- 讲师介绍 -->
    <section class="teacher-info">
      <div class="teacher-avatar">
        <img :src="teacher.avatar" alt="讲师头像" />
      </div>
      <div class="teacher-details">
        <h3 class="teacher-name-level">
          {{ teacher.name }}
          <span v-if="teacher.level === 1"> 高级讲师</span>
          <span v-else-if="teacher.level === 2"> 特级讲师</span>
        </h3>
        <div class="teacher-career">{{ teacher.career }}</div>
        <p class="teacher-intro">{{ teacher.intro }}</p>
      </div>
    </section>

    <!-- 无数据提示 -->
    <section class="no-data-wrap" v-if="courseList.length === 0">
      <em class="no-data-ico"></em>
      <span class="no-data-text">没有相关数据，小编正在努力整理中...</span>
    </section>

    <!-- 课程列表 -->
    <section class="comm-course-list" v-if="courseList.length > 0">
      <ul class="course-list">
        <li v-for="course in courseList" :key="course.id" class="course-item">
          <div class="course-img-wrapper">
            <img :src="course.cover" :alt="course.title" />
            <div class="course-mask">
              <a :href="`/course/${course.id}`" target="_blank" class="btn-learn">开始学习</a>
            </div>
          </div>
          <h3 class="course-title">
            <a :href="`/course/${course.id}`" target="_blank" :title="course.title">{{ course.title }}</a>
          </h3>
        </li>
      </ul>
    </section>
  </div>
</template>

<script>
import teacherApi from '@/api/teacher'

export default {
  data() {
    return {
      teacher: {},
      courseList: []
    }
  },
  async asyncData({ params }) {
    const response = await teacherApi.getTeacherInfo(params.id)
    return {
      teacher: response.data.data.teacher.data || {},
      courseList: response.data.data.courseList.data || []
    }
  }
}
</script>

<style scoped>
.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px;
  font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
  color: #333;
  background: #fafafa;
}

/* 讲师介绍 */
.teacher-info {
  display: flex;
  align-items: flex-start;
  background: #fff;
  padding: 20px;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgb(0 0 0 / 0.1);
  margin-bottom: 30px;
}

.teacher-avatar img {
  width: 160px;
  height: 160px;
  object-fit: cover;
  border-radius: 50%;
  border: 2px solid #ddd;
}

.teacher-details {
  margin-left: 24px;
  flex: 1;
}

.teacher-name-level {
  font-size: 24px;
  font-weight: 600;
  margin-bottom: 8px;
  color: #222;
}

.teacher-career {
  display: inline-block;
  background: #007bff;
  color: white;
  padding: 4px 12px;
  border-radius: 12px;
  font-size: 14px;
  margin-bottom: 16px;
}

.teacher-intro {
  line-height: 1.6;
  font-size: 16px;
  color: #555;
}

/* 无数据提示 */
.no-data-wrap {
  text-align: center;
  padding: 60px 0;
  color: #999;
  font-size: 18px;
  display: flex;
  justify-content: center;
  align-items: center;
}

.no-data-ico {
  font-size: 48px;
  margin-right: 12px;
}

.no-data-text {
  font-size: 18px;
}

/* 课程列表 */
.comm-course-list {
  background: #fff;
  padding: 20px;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgb(0 0 0 / 0.1);
}

.course-list {
  display: flex;
  flex-wrap: wrap;
  gap: 20px;
  list-style: none;
  padding: 0;
  margin: 0;
}

.course-item {
  width: calc(25% - 15px);
  display: flex;
  flex-direction: column;
  background: #fefefe;
  border-radius: 6px;
  overflow: hidden;
  box-shadow: 0 1px 5px rgb(0 0 0 / 0.1);
  transition: box-shadow 0.3s ease;
}

.course-item:hover {
  box-shadow: 0 4px 12px rgb(0 0 0 / 0.15);
}

.course-img-wrapper {
  position: relative;
  overflow: hidden;
  height: 140px;
}

.course-img-wrapper img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform 0.3s ease;
}

.course-img-wrapper:hover img {
  transform: scale(1.05);
}

.course-mask {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0, 123, 255, 0.6);
  opacity: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  transition: opacity 0.3s ease;
}

.course-img-wrapper:hover .course-mask {
  opacity: 1;
}

.btn-learn {
  background: #fff;
  color: #007bff;
  padding: 8px 16px;
  border-radius: 20px;
  text-decoration: none;
  font-weight: 600;
  box-shadow: 0 2px 6px rgba(0, 123, 255, 0.4);
}

.course-title {
  font-size: 16px;
  font-weight: 500;
  color: #222;
  padding: 12px 16px;
  flex: 1;
}

.course-title a {
  color: inherit;
  text-decoration: none;
}

.course-title a:hover {
  text-decoration: underline;
}

/* 响应式调整 */
@media (max-width: 1024px) {
  .course-item {
    width: calc(33.333% - 13.33px);
  }
}

@media (max-width: 768px) {
  .teacher-info {
    flex-direction: column;
    align-items: center;
    text-align: center;
  }
  .teacher-details {
    margin-left: 0;
    margin-top: 20px;
  }
  .course-item {
    width: calc(50% - 10px);
  }
}

@media (max-width: 480px) {
  .course-item {
    width: 100%;
  }
}
</style>
